package com.cy.factory;

import com.cy.service.RemoteProviderService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author tang
 * @data 2021/9/16
 * @apiNode
 */
@Component
//org.slf4j.Logger是Java中的日志规范,定义了一个接口
//org.slf4j.Logger这个接口的实现有log4j,logback

public class RempteFallBackFactory implements FallbackFactory<RemoteProviderService> {

    private static final Logger log = LoggerFactory.getLogger(RempteFallBackFactory.class);
    //@Override
    //public RemoteProviderService create(Throwable throwable) {
    //    return new RemoteProviderService(){
    //
    //        @Override
    //        public String echoMessage(String msg) {
    //            return "查询时间过长，请耐心等待";
    //        }
    //    };
    //}
    @Override
    public RemoteProviderService create(Throwable throwable) {
        log.error("需要等的时间有点成哦{}",throwable.getMessage());
        //简化形式如下:借助了jdk8中lambda表达式
        return msg -> "查询时间过长，请耐心等待";
    }
}
